<?php
/* +----------------------------------------------------------------------
   | 管理员控制器
   +----------------------------------------------------------------------*/
namespace Home\Controller;
use Think\Controller;
Class XycruleController extends Controller{
	public function __construct(){
		parent::__construct();
	}

	/**
	 * 信用查芝麻分规则查询接口 检查用户芝麻分是否在563分以上
	 * @author spz
	 * @date 2018/6/26 18:00
	 */
	public function k0042($name,$id_card)
	{
		header("Content-type: text/html; charset=utf-8");
//		if(!empty($_POST)){
//			$name=I('name');
//			$id_card=I('id_card');
			if(empty($name)||empty($id_card)){
				$json = json_encode(array('status' => '1004', 'result' => '数据缺失,方法无法执行'),JSON_UNESCAPED_UNICODE);
				echo $json;exit;
			}
			$url = 'http://fk.56etrip.com/Zm/get_zm';
			$data['name'] = $name;//道森坦利账号
			$data['id_card'] = $id_card;//道森坦利密码
			$data['timestamp'] = time();
			$data['token'] = '6bd00789f769c256cbf2f770b382cd5b';
			$data['sign'] = $data['timestamp'].'+'.$data['token'].'+nxyc.dstlkj.com';
			$data['sign'] =md5($data['sign']);
			$result = self::set_curl($url, $data);
			$url = 'http://fk.56etrip.com/Zm/get_result';
			$result2 = self::set_curl($url, $data);
			$result2=json_decode($result2,true,JSON_UNESCAPED_UNICODE);
			$save=['name'=>$data['name'],'id_card'=>$data['id_card'],'ret'=>$result2['ret'],'code'=>$result2['code'],'res'=>$result2['res'],'err_msg'=>$result2['err_msg'],'ctime'=>time()];
			M('zm_result','','DB2_ZX')->add($save);
			if($result2['ret']=='1001'){
				if($result2['res']=='2'){
					$json = json_encode(['status' => '1001', 'result' =>'pass'],JSON_UNESCAPED_UNICODE);
				}else{
					$json = json_encode(['status' => '1002', 'result' => 'nopass'],JSON_UNESCAPED_UNICODE);
				}
			}else{
				$json = json_encode(['status' => '1003', 'result' => $result2['err_msg']],JSON_UNESCAPED_UNICODE);
			}
			return $json;
//		}else{
//			$json = json_encode(['status' => '9999', 'result' => '错误的访问方式'],JSON_UNESCAPED_UNICODE);
//			echo $json;
//		}
	}
    public function get_k0042()
    {
        header("Content-type: text/html; charset=utf-8");
        if(!empty($_POST)){
            $name=I('name');
            $id_card=I('id_card');
            if(empty($name)||empty($id_card)){
                $json = json_encode(array('status' => '1004', 'result' => '数据缺失,方法无法执行'),JSON_UNESCAPED_UNICODE);
                echo $json;exit;
            }
            $url = 'http://fk.56etrip.com/Zm/get_zm';
            $data['name'] = $name;//道森坦利账号
            $data['id_card'] = $id_card;//道森坦利密码
            $data['timestamp'] = time();
            $data['token'] = '6bd00789f769c256cbf2f770b382cd5b';
            $data['sign'] = $data['timestamp'].'+'.$data['token'].'+nxyc.dstlkj.com';
            $data['sign'] =md5($data['sign']);
            $result = self::set_curl($url, $data);
//			$result=json_decode($result,true);
//			$json1 = json_encode(array('status' => '1001', 'result' => $result),JSON_UNESCAPED_UNICODE);

            $url = 'http://fk.56etrip.com/Zm/get_result';
            $result2 = self::set_curl($url, $data);
            $result2=json_decode($result2,true,JSON_UNESCAPED_UNICODE);
            $save=['name'=>$data['name'],'id_card'=>$data['id_card'],'ret'=>$result2['ret'],'code'=>$result2['code'],'res'=>$result2['res'],'err_msg'=>$result2['err_msg'],'ctime'=>time()];
            #'XYC'=> 'mysql://xyc_user:Xyc_user0571@sh-cdb-e7o35ybo.sql.tencentcdb.com:63039/xyc#utf8',//远端通讯通话记录服务器
            M('zm_result','','DB2_ZX')->add($save);
            if($result2['ret']=='1001'){
                if($result2['res']=='2'){
                    $json = json_encode(['status' => '1001', 'result' =>'pass'],JSON_UNESCAPED_UNICODE);
                }else{
                    $json = json_encode(['status' => '1002', 'result' => 'nopass'],JSON_UNESCAPED_UNICODE);
                }
            }else{
                $json = json_encode(['status' => '1003', 'result' => $result2['err_msg']],JSON_UNESCAPED_UNICODE);
            }
            echo $json;
        }else{
            $json = json_encode(['status' => '9999', 'result' => '错误的访问方式'],JSON_UNESCAPED_UNICODE);
            echo $json;
        }
    }
	static function set_curl($url, $data = array(), $header = '')
	{
		$ch = curl_init();
		if (!empty($header)) {
			//        $header=array('Content-type: application/json','charset:utf-8'); 示例
			curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
		}
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, '1');
		curl_setopt($ch, CURLOPT_URL, $url);
		if (!empty($data)) {
			curl_setopt($ch, CURLOPT_POST, '1');
			curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		}
		//	curl_setopt($ch, CURLOPT_TIMEOUT,5);   //只需要设置一个秒的数量就可以
		//禁用后cURL将终止从服务端进行验证
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		$res = curl_exec($ch);
		if (curl_error($ch)) {
			return '错误信息:' . curl_error($ch);
		}
		curl_close($ch);
		return $res;
	}
    public function mobile_clear_start($mobile=null){
        $this->mobile_clear_start2_0($mobile);
    }
    public function mobile_clear_start2_0($mobile=null){//改为本地list处理已完毕，改变保存表即可投入使用20180418 15:12
        if(empty($mobile)){
            $json = json_encode(array('status' => 1002, 'result' => '缺少参数'),JSON_UNESCAPED_UNICODE);
            echo $json;exit;
        }
        $db_yw  ='mysql://xyc_user:Xyc_user0571@sh-cdb-e7o35ybo.sql.tencentcdb.com:63039/xyc#utf8';//信用查服务器
        $is_true=M('user','',$db_yw)->where(['mobile'=>$mobile])->getfield('id');
        if(empty($is_true)){
            $json = json_encode(array('status' => 1002, 'result' => '用户不存在'),JSON_UNESCAPED_UNICODE);
            echo $json;exit;
        }
        $data=M('user_mobile_clear_yy','',$db_yw)->where(['mobile'=>$mobile])->find();
        if(!empty($data)){
            $json = json_encode(array('status' => 1001, 'result' => $data),JSON_UNESCAPED_UNICODE);
            echo $json;exit;
        }else{
            $Outport=new XycmobileclearController();
            $data=$Outport->mobile_clear2_0($mobile);
            M('user_mobile_clear_yy','',$db_yw)->add($data);
            $json = json_encode(array('status' => 1001, 'result' => $data),JSON_UNESCAPED_UNICODE);
            echo $json;exit;
        }
        $json = json_encode(array('status' => 1002, 'result' => '逻辑存在异常情况'),JSON_UNESCAPED_UNICODE);
    }
}
?>